import axios from 'axios';
//引入进度条
import nprogress from "nprogress";
//引入进度条样式
import "nprogress/nprogress.css"
const service = axios.create({
    baseURL: 'http://www.car.ttblog.cn/api',
    // baseURL: 'http://192.168.0.159:8090/htsystem',
    timeout: 5000,
})


service.interceptors.request.use(
    config => {
        if (localStorage.getItem('userInfo')) {
            config.headers.token = JSON.parse(localStorage.getItem('userInfo')).token
        }
        nprogress.start()
        return config;
    },
    error => {
        console.log(error);
        return Promise.reject();
    }
);

service.interceptors.response.use(
    response => {
        nprogress.done()
        if (response.status === 200) {
            return response.data;
        } else {
            Promise.reject();
        }
    },
    error => {
        nprogress.done()
        console.log(error);
        return Promise.reject();
    }
);
export default service;
